home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / tvexit.exe / TVEXIT.CPP < prev    next >
C/C++ Source or Header  |  1992-08-10  |  4KB  |  179 lines

  1.  
  2. //========================================================================
  3. //  The following example routines have been provided by the Technical
  4. //  Support staff at Borland International.  They are provided as a
  5. //  courtesy and not as part of a Borland product, and as such, are
  6. //  provided without the assurance of technical support or any specific
  7. //  guarantees.
  8. //========================================================================
  9. //
  10. //     TVeXIT:
  11. //     This program is an example of controling the dos screen upon exit.
  12. //     Use of  "#pragma exit <function name>" allows our function to be
  13. //     destroyed after the screen has been destructed.  Notice the priority
  14. //     number of 31.  Since constructors and destructors have priority of
  15. //     32, 31 causes the destructor( for exit_func ) to be called after
  16. //     the screen destructor.
  17. //
  18. //========================================================================
  19. #define Uses_TApplication
  20. #define Uses_TStaticText
  21. #define Uses_TEventQueue
  22. #define Uses_TEvent
  23. #define Uses_TKeys
  24. #define Uses_TRect
  25. #define Uses_TMenuBar
  26. #define Uses_TSubMenu
  27. #define Uses_TMenuItem
  28. #define Uses_TStatusLine
  29. #define Uses_TStatusItem
  30. #define Uses_TStatusDef
  31. #define Uses_TDeskTop
  32. #define Uses_TView
  33. #define Uses_TWindow
  34. #define Uses_TMenu
  35. #define Uses_TDialog
  36. #define Uses_TButton
  37.  
  38. #include <string.h>   //for strcmp()
  39. #include <stdlib.h>
  40. #include <tv.h>
  41.  
  42. const int cmAbout = 100;
  43.  
  44. int exit_flag = 1;    // use this to keep track of exit.
  45.  
  46. class TMyApp : public TApplication
  47. {
  48.  
  49. public:
  50.     TMyApp();
  51.   static TMenuBar *initMenuBar( TRect );
  52.     static TStatusLine *initStatusLine( TRect );
  53.     void handleEvent(TEvent& event);
  54.     void AboutDialog(void);
  55.  
  56. };
  57.  
  58.  
  59. TMyApp::TMyApp() :
  60.     TProgInit( &initStatusLine,
  61.            &initMenuBar,
  62.            &initDeskTop
  63.          )
  64. {
  65. }
  66.  
  67.  
  68. void TMyApp::AboutDialog(void)
  69. {
  70.     char Text[] = "\003TvExit\n\n\n\n"
  71.                  "\003Shows you how to control the\n"
  72.                  "\003screen upon exit.";
  73.  
  74.  
  75.     TDialog *pd = new TDialog( TRect( 20,2,60,18), "About");
  76.     if( validView(pd) )
  77.     {
  78.       pd->insert( new TStaticText( TRect( 5, 2, 35, 12), Text));
  79.       deskTop->execView(pd);
  80.     }
  81.  
  82.     destroy(pd);
  83.  
  84. }
  85.  
  86.  
  87.  
  88. void TMyApp::handleEvent(TEvent& event)
  89. {
  90.    TApplication::handleEvent( event );
  91.  
  92.    if( event.what == evCommand )
  93.    {
  94.       switch( event.message.command)
  95.       {
  96.     case cmAbout:
  97.       AboutDialog();
  98.       break;
  99.  
  100.     default:
  101.       break;
  102.       }
  103.       clearEvent( event );
  104.    }
  105. }
  106.  
  107.  
  108. TStatusLine *TMyApp::initStatusLine(TRect r)
  109. {
  110.    r.a.y = r.b.y - 1;
  111.  
  112.    return new TStatusLine( r,
  113.        *new TStatusDef( 0, 0xFFFF) +
  114.        *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit) +
  115.        *new TStatusItem( "~Alt-A~ About", kbAltA, cmAbout)
  116.        );
  117.  
  118. }
  119.  
  120.  
  121. TMenuBar *TMyApp::initMenuBar( TRect r )
  122. {
  123.     r.b.y = r.a.y + 1;
  124.     TMenuBar *t;
  125.  
  126.    TMenuItem *two =
  127.       new TMenuItem("~E~xit", cmQuit, kbAltX);
  128.  
  129.    TMenuItem *one =
  130.       new TMenuItem("~\xF0~", kbAltSpace,
  131.     new TMenu( *new TMenuItem("~A~bout", cmAbout, kbAltA)),
  132.       hcNoContext, two);
  133.  
  134.     return ( new TMenuBar( r, new TMenu( *one ) )  );
  135.  
  136.  
  137. }
  138.  
  139.  
  140.  
  141. //-------------------------------------------------------------------
  142. //   This is the function which is called upon exit if exit_flag is
  143. //   still equal to 1. Exit_flag is set to zero in main if the user
  144. //   inputs the appropriate command line parameter,i.e., "hello."
  145. //-------------------------------------------------------------------
  146. void exitfunc(void)
  147. {
  148.   if( exit_flag )
  149.   {
  150.      cout << "Syntax: tvexit hello\n" << endl;
  151.      cout << "\nPlease enter ""hello"" after the program name." << endl;
  152.   }
  153.  
  154. }
  155.  
  156.  
  157. //----------------------------------------------------------------------
  158. //  #pragma :
  159. //  Use priority 31 because the priority of constructors and destructors
  160. //  (currently) is 32, thus, my function is constructed before and
  161. //  destructed after the TScreen object.
  162. //----------------------------------------------------------------------
  163.  
  164. #pragma exit exitfunc  31
  165.  
  166.  
  167. int main(int argc, char *argv[])
  168. {
  169.  
  170.   if( strcmp(argv[1], "hello")  )
  171.    return -1;
  172.  
  173.    TMyApp myApp;
  174.    myApp.run();
  175.    exit_flag = 0;  // turn exit flag off
  176.    return 0;
  177.  
  178. }
  179.